package com.example.interceptor;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;


import java.util.Base64;

/**
 * @desc 共用信息
 * @author shishumin
 * @date 2024/10/11 17:39
 */
@Data
public class SSOSessionData {
    private String userId;
    private String username;
    private String realm;
    private String appId;
    private String realmName;

    public SSOSessionData(String userId, String username, String realm, String appId) {
        this.userId = userId;
        this.username = username;
        this.realm = realm;
        this.appId = appId;
        this.realmName = "";
    }

    public SSOSessionData(String userId, String username, String realm, String appId, String realmName) {
        this.userId = userId;
        this.username = username;
        this.realm = realm;
        this.appId = appId;
        this.realmName = realmName;
    }

    public static void main(String[] args) {
        SSOSessionData ssoSessionData = new SSOSessionData("u23311", "user1", "tenantId","appId");
        byte[] encode = Base64.getEncoder().encode(JSON.toJSONBytes(ssoSessionData));
        System.out.println(encode);

        byte[] decode = Base64.getDecoder().decode(encode);
        String s= "eyJyZWFsbU5hbWUiOiLns7vnu5/np5/miLciLCJyb2xlcyI6WyIxIiwiOTQ5NDQzNTcyMjAzNTIwMCJdLCJhcHBJZCI6IjEwMjczMjE5MjAzNjk0NTkyIiwicmVhbG0iOiIwIiwidXNlcm5hbWUiOiJkZXZUWlEiLCJ1c2VySWQiOiI5ODMwOTA2NzExNzY5MDg4In0=";
        SSOSessionData sessionData2 = com.alibaba.fastjson.JSON.parseObject(Base64.getDecoder().decode(s), SSOSessionData.class);
        System.out.println(JSONObject.toJSONString(sessionData2));
    }
}